package will.android;

import android.os.Handler;
import android.widget.TextView;

public class Task implements Runnable
{
   private TextView display;
   private Handler  mHandler = new Handler();
   private int      nCounter = 0;
   private long orderTime = 0L;

   public Task(TextView display, long orderTime)
   {
      this.orderTime = orderTime;
      this.display = display;
      mHandler.removeCallbacks(this);
      mHandler.postDelayed(this, 1000);
   }
   
   public long convertTime(int fourDigit)
   {
      
      return fourDigit;
      
   }

   @Override
   public void run()
   {
      long start = orderTime;
      long elapseTime = System.currentTimeMillis() - start;
      int seconds = (int) (elapseTime / 1000);
      int minutes = seconds / 60;
      seconds     = seconds % 60;

      if (seconds < 10) {
          display.setText("" + minutes + ":0" + seconds);
      } else {
          display.setText("" + minutes + ":" + seconds);            
      }

      // add a delay to adjust for computation time
      long delay = (1000 - (elapseTime%1000));

      mHandler.postDelayed(this, delay);

      //nCounter++;

      //display.setText("Hallo from thread counter: " + nCounter);
      //mHandler.postDelayed(this, 1000);
      
   }
}